package com.ssy.lingxi.dataauth.builder;

import com.ssy.lingxi.dataauth.model.dto.ChannelAuthMemberDto;
import net.sf.jsqlparser.JSQLParserException;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 测试类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-04-08
 */
public class BuilderTest {
    public static void main(String[] args) throws JSQLParserException {
        String sql = "select memberdo0_.id as id1_7_0_, memberdo0_.account as account2_7_0_, memberdo0_.auth as auth3_7_0_, memberdo0_.country_code as country_4_7_0_, memberdo0_.detail as detail5_7_0_, memberdo0_.email as email6_7_0_, memberdo0_.logo as logo7_7_0_, memberdo0_.name as name8_7_0_, memberdo0_.password as password9_7_0_, memberdo0_.pay_password as pay_pas10_7_0_, memberdo0_.phone as phone11_7_0_, memberdo0_.register_time as registe12_7_0_, memberdo0_.source as source13_7_0_, roles1_.member_id as member_i1_41_1_, roledo2_.id as role_id2_41_1_, roledo2_.id as id1_36_2_, roledo2_.auth as auth2_36_2_, roledo2_.business_type_id as business6_36_2_, roledo2_.config_auth as config_a3_36_2_, roledo2_.member_type_id as member_t7_36_2_, roledo2_.role_name as role_nam4_36_2_, roledo2_.role_type_id as role_typ8_36_2_, roledo2_.status as status5_36_2_, memberbusi3_.id as id1_9_3_, memberbusi3_.business_type_name as business2_9_3_, membertype4_.id as id1_30_4_, membertype4_.type_enum as type_enu2_30_4_, membertype4_.type_name as type_nam3_30_4_, roletypedo5_.id as id1_37_5_, roletypedo5_.role_type_name as role_typ2_37_5_, roletypedo5_.type_enum as type_enu3_37_5_ from public.ms_mc_member memberdo0_ left outer join ms_mc_member_role_relation roles1_ on memberdo0_.id = roles1_.member_id left outer join public.ms_mc_role roledo2_ on roles1_.role_id = roledo2_.id left outer join public.ms_mc_member_business_type memberbusi3_ on roledo2_.business_type_id = memberbusi3_.id left outer join public.ms_mc_member_type membertype4_ on roledo2_.member_type_id = membertype4_.id left outer join public.ms_mc_role_type roletypedo5_ on roledo2_.role_type_id = roletypedo5_.id where memberdo0_.id = ? or memberdo0_.age = ?";

        List<ChannelAuthMemberDto> members = new ArrayList<>();
        ChannelAuthMemberDto m1 = new ChannelAuthMemberDto(1L, 2L);
        ChannelAuthMemberDto m2 = new ChannelAuthMemberDto(2L, 3L);
        members.add(m1);
        members.add(m2);

        PgSqlStatementBuilder.simpleSelectBuilder()
                .fromSql(sql)
                .specifyTable("")
                .addWhere("member_id", "role_id", "user_id", Stream.of(1L, 2L).collect(Collectors.toList()), members)
                .buildSql()
                .showExecSql()
                .toSql();
    }

}
